package dch.struts2.admin.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import dch.entity.Page;
import dch.service.admin.dao.AcommentService;
import dch.service.admin.impl.AcommentServiceImpl;

@Namespace("/acomment")
@Result(name="clist",location="/jsp/admin/listAcomment.jsp")
public class AcommentAction {

	private AcommentService acommentService=null;
	private int id;
	private String keyword=null;
	private int currentPage=1;
	private dch.entity.Result	result			=null;
	private HttpServletResponse response		=null;
	
	public AcommentAction(){
		acommentService=new AcommentServiceImpl();
	}
	public String execute(){
		return null;
	}
	
	@Action("/acDelete")
	public void commentDelete(){
		
		response=ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter out=null;
		try {
			out=response.getWriter();
			if(id!=0){
				acommentService.deleteComment(id);
				out.println("success");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(out!=null)
				out.close();
			acommentService.close();
		}
	}
	

	@Action("/commentlist")
	public String commentList(){
		Page page=new Page(currentPage);
		result=acommentService.listCommentByPage(page,keyword);
		acommentService.close();
		return "clist";
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public dch.entity.Result getResult() {
		return result;
	}

	public void setResult(dch.entity.Result result) {
		this.result = result;
	}
	
	
}
